#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@File    :   admin.py
@Time    :   2025/10/30 08:44:29
@Author  :   Rico Chen 
@Mail    :   55059@qq.com
@Version :   1.0
@Desc    :   自定义首页
'''
from core.globals import auth, scheduler, site
from core.settings import settings
from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi_amis_admin_nav.admin import NavPageAdmin
from sqlmodel import SQLModel
from starlette.responses import RedirectResponse
from starlette.requests import Request
from fastapi import Depends
from fastapi_user_auth.auth.models import User
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from fastapi_amis_admin_offline import patch_offline
from fastapi_amis_admin.admin import HomeAdmin
from fastapi_amis_admin.amis.components import Page
from fastapi_amis_admin import amis
from fastapi_amis_admin.amis.components import Page, PageSchema, Property

# 取消默认首页
site.unregister_admin(HomeAdmin)
# 注册自定义首页
@site.register_admin
class MyHomeAdmin(HomeAdmin):
    page_schema = PageSchema(label="首页", icon="fa fa-home", url="/home", isDefaultPage=True, sort=100)
    page_path = "/home"
    async def get_page(self, request: Request) -> Page:
        # 获取默认页面
        page = await super().get_page(request)
        page.body = [
            Property(
                title=settings.site_title,
                column=4,
                items=[
                    Property.Item(label="站点名称", content=self.site.settings.site_title),
                    Property.Item(label="版本", content=self.site.settings.version),
                    Property.Item(label="语言", content=self.site.settings.language),
                    Property.Item(label="调试模式", content=str(self.site.settings.debug)),
                ],
            ),
            amis.Divider(),
            Property(
                title="站点信息",
                column=4,
                items=[
                    Property.Item(label="操作系统", content="linux"),
                    Property.Item(label="开发语言", content="python,fastapi"),
                    Property.Item(label="版本", content=self.site.settings.version),
                    Property.Item(label="数据库", content="MySQL"),
                    Property.Item(label="公司", content="公诚管理咨询有限公司"),
                    Property.Item(label="作者", content="东莞分公司"),
                    Property.Item(label="风格", content=self.site.settings.amis_theme),
                    Property.Item(label="orm", content="sqlmodel"),
                    Property.Item(label="联系", content="郝奎收"),
                    Property.Item(label="amis-cdn", content=self.site.settings.amis_cdn),
                    Property.Item(label="amis-pkg", content=self.site.settings.amis_pkg),
                    Property.Item(label="amis-theme", content=self.site.settings.amis_theme),
                ],
            ),
        ]
        return page
